<form class="layui-form" id="admin_edit" lay-filter="admin_edit">
  <div class="tplay-body">
    <div class="layui-row layui-col-space15">
      <script id="editAdmin" type="text/html">
      <div class="layui-col-md6">
          <div class="layui-card-header">账户信息</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <input type="text" placeholder="用户名" autocomplete="off" class="layui-input" value="{{ d.data.admin.username }}" disabled>
              <input type="hidden" name="id" value="{{ d.data.admin.id }}">
            </div>
          </div>
        <div class="layui-form" lay-filter="component-form-element">
          <div class="layui-card-header">基本资料</div>
            <div class="layui-card-body layui-row layui-col-space10">
              <div class="layui-col-md6">
                <input type="text" required name="nickname" placeholder="昵称" autocomplete="off" class="layui-input" value="{{ d.data.admin.nickname }}">
              </div>
              <div class="layui-col-md6">
                <input type="text" name="phone" required placeholder="手机号" autocomplete="off" class="layui-input" value="{{ d.data.admin.phone }}">
              </div>
            </div>
        </div>
        <div class="layui-form" lay-filter="component-form-element">
          <div class="layui-card-header">性别</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <input type="radio" name="sex" value="1" title="男" {{# if(d.data.admin.sex == 1){ }}checked{{# } }}>
              <input type="radio" name="sex" value="0" title="女" {{# if(d.data.admin.sex == 0){ }}checked{{# } }}>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-col-md6">
          <div class="layui-card-header">备注</div>
          <div class="layui-card-body layui-row layui-col-space10">
            <div class="layui-col-md12">
              <textarea name="desc" placeholder="请输入" class="layui-textarea">{{ d.data.admin.desc }}</textarea>
            </div>
          </div>
          <div class="layui-card-header">权限管理</div>
          <div class="layui-card-body">
            <div class="layui-form">
              <div class="layui-form-item">
                <label class="layui-form-label">权限分组：</label>
                    <div class="layui-form layui-input-block">
                      {{# for(var i = 0;i< d.data.group.length;i++){ }}
                          <input type="checkbox" name="group_id[]" title="{{ d.data.group[i].title }}" value="{{ d.data.group[i].id }}" {{# for(var s = 0;s< d.data.admin_group.length;s++){ }}{{# if(d.data.group[i].id == d.data.admin_group[s].group_id){ }}checked{{# } }}{{# } }}>
                      {{# } }}
                    </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn" lay-submit lay-filter="component-form-element">立即提交</button>
                  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
              </div>
            </div>
          </div>
      </div>
      </script>
      <div id="edit_view"></div>
    </div>
  </div>
</form>
<script type="text/javascript">
layui.use(['form','laytpl','tplay','route','apiconfig'], function(){
  var $ = layui.$
  ,element = layui.element
  ,laytpl = layui.laytpl
  ,form = layui.form
  ,tplay = layui.tplay
  ,route = layui.route
  ,config = layui.apiconfig;
  tplay.ajax({
    url:config.domain+"/admin/admin/edit",
    type:'get',
    data:{id:route.params().id},
    async:false,success:function(res){
      if(res.code == 1){
        var editTpl = $('#editAdmin').html()
        ,view = document.getElementById('edit_view');
        laytpl(editTpl).render(res, function(html){
          view.innerHTML = html;
        });
      } else {
        layer.msg(res.msg);
      }
    }
  });

  form.render(null, 'admin_edit');
  
  form.on('submit(component-form-element)', function(data){
    tplay.ajax({
      url:config.domain+"/admin/admin/edit",
      type:"post",
      data:$('#admin_edit').serialize(),
      success:function(res){
        layer.msg(res.msg);
        if(res.code == 1){
          tplay.goBack(1000);
        }
      }
    })
    return false;
  });
});
</script>